package com.hjl.cookies;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * @author ServivE
 * @version 0.1
 * @className EncodeCookieservlet
 * @description
 * @date 2024/7/27 14:51
 * @since jdk11
 */
@WebServlet("/cs3")
public class EncodeCookieServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie cookie = new Cookie(
                URLEncoder.encode("姓名", "UTF-8"),
                URLEncoder.encode("张三", "UTF-8")
        );
        response.addCookie(cookie);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
